Skip to content

Comments

Taks 1 and 2 done.#2

Open
yarikpavlin wants to merge 2 commits intoChangeRequest:masterfrom
yarikpavlin:master
Open

Taks 1 and 2 done.#2
yarikpavlin wants to merge 2 commits intoChangeRequest:masterfrom
yarikpavlin:master

Conversation

@yarikpavlin
Copy link

3 task will be done soon

@xSAVIKx xSAVIKx self-assigned this Dec 26, 2016
Copy link
Member

@xSAVIKx xSAVIKx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check comments below, provide demo for Container implementation and try to solve last task.

return true;
if(a == null || b == null)
return false;
if(a.getKey() == b.getKey() && a.getValue() == b.getValue())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use equals method, cause == will check if objects point to the same part in memory

int count = 0;
for(int i = 0; i < a.length; i++)
{
if(key.compareTo(a[i].getKey()) == -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CompareTo can return any negative number, not only -1

*/
public class TestingApp {
public static void main(String[] args) {
Pair p1 = new Pair<>(1,"k1");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your pairs should be initialized with some Generics, you should not use raw notation, so please, use smth like:

Pair<Integer,String> p1 = new Pair<>(1,"k1");

Pair p2 = new Pair<>(2,"k2");
Pair p4 = new Pair<>(3,"k3");

Pair[] pA = new Pair[3];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for array. you shouldn't use raw types.


ContainerImpl()
{
this.array = (E[]) new Object[10];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that such class cast will work. You cannot cast Object to Type E[].

Please provide Demo class for Container to check whether your implementation work correctly.
Provide demo for all operations for some 2 different Generic type, for example: String and Float.

/**
* Created by Yaroslav Pavlinskiy on 22.12.2016.
*/
public class TestingApp {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your Demo class should provide demo for all possible operations with 2 or 3 different pair types ( for example: <String,Integer>, <Double, Float>, <Integer, Container>)


public static <K extends Comparable<K>,V> int compareTo(Pair<K,V> a,Pair<K,V> b)
{
return a.getKey().compareTo(b.getKey());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about NullPointerException checks ? (Please add them for all methods)

this.key = key;
}

public boolean contains(K key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is quite weird, cause it not really check whether given pair contains smth. It just check whether some key is exactly same object as key from the pair. (also, you should not use ==, but use equals instead).

* Created by Yaroslav Pavlinskiy on 22.12.2016.
*/
public class Pair <K,V> {
protected V value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need fields to be protected ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants